home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.06 Jun 91 / OQD Code / OQD.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-10  |  2.5 KB  |  116 lines  |  [TEXT/KAHL]

  1. /************************************
  2. Program name:  OQD.c
  3. Function:  Demos Old QuickDraw Color Tricks. 
  4. ************************************/
  5.  
  6. #include "OQD_Test.h"
  7.  
  8. #define      TRUE   1
  9. #define      FALSE  0
  10. #define      NIL    0
  11.  
  12. /* initial color selection */
  13. int colorSelection[4] = { whiteColor, blackColor, whiteColor, blackColor};
  14.  
  15. /* external functions */
  16. extern void InitMyMenus(void);
  17. extern void HandleMenu(char *doneFlag, short theMenu, short theItem);
  18.  
  19. void main(void);
  20.  
  21. void main()
  22. {
  23. char doneFlag, ch;
  24. short code, theMenu, theItem, chCode;
  25. long mResult;
  26. WindowPtr whichWindow;
  27. EventRecord myEvent;
  28. Rect tempRect;
  29. GrafPtr SavePort;
  30.  
  31. /* initialize everything */
  32. InitGraf(&thePort);
  33. InitFonts();
  34. FlushEvents(everyEvent,0);
  35. InitWindows();
  36. InitMenus();
  37. TEInit();
  38. InitDialogs(NIL);
  39. InitCursor();
  40.  
  41. /* initialize my own stuff */
  42. doneFlag = FALSE;
  43. InitMyMenus();
  44. Init_OQD_Test();
  45. Open_OQD_Test();
  46.  
  47. do {
  48.     SystemTask();
  49.  
  50.     if (GetNextEvent(everyEvent, &myEvent)) {
  51.         code = FindWindow(myEvent.where, &whichWindow);    
  52.  
  53.         switch (myEvent.what) {
  54.             case mouseDown:
  55.                 if (code == inMenuBar) {
  56.                     mResult = MenuSelect(myEvent.where);
  57.                     theMenu = HiWord(mResult);
  58.                     theItem = LoWord(mResult);
  59.                     HandleMenu(&doneFlag,theMenu,theItem);
  60.                     }
  61.  
  62.                  if ((code == inDrag)&&(whichWindow != NIL)) {
  63.                     tempRect = screenBits.bounds;
  64.                     SetRect(&tempRect, tempRect.left + 10, tempRect.top + 25, tempRect.right - 10, tempRect.bottom - 10);
  65.                     DragWindow(whichWindow, myEvent.where, &tempRect);
  66.                     }
  67.   
  68.                 if (code == inContent) {
  69.                     if (whichWindow != FrontWindow()) {
  70.                         SelectWindow(whichWindow);
  71.                         }
  72.                     else {
  73.                         SetPort(whichWindow);
  74.                         Do_OQD_Test (&myEvent);
  75.                         }
  76.                     }
  77.  
  78.                 if (code == inSysWindow) {
  79.                     SystemClick(&myEvent, whichWindow);
  80.                     }
  81.  
  82.                 break;
  83.  
  84.             case keyDown: 
  85.             case autoKey: 
  86.                 ch = myEvent.message &  charCodeMask;
  87.                 if (myEvent.modifiers & cmdKey) {
  88.                     mResult = MenuKey(ch);
  89.                     theMenu = HiWord(mResult);
  90.                     theItem = LoWord(mResult);
  91.                     if (theMenu != 0) 
  92.                         HandleMenu(&doneFlag, theMenu, theItem); 
  93.                     }
  94.                 break;
  95.  
  96.             case updateEvt:
  97.                 whichWindow = (WindowPtr)myEvent.message;
  98.                 GetPort(&SavePort);
  99.                 BeginUpdate(whichWindow);
  100.                 SetPort(whichWindow);
  101.                     UpDate_OQD_Test(whichWindow);
  102.                 EndUpdate(whichWindow);
  103.                 SetPort(SavePort);
  104.                 break;
  105.  
  106.             case activateEvt:
  107.                 if ((whichWindow != NIL) && (myEvent.modifiers & activeFlag)) { 
  108.                     SelectWindow(whichWindow);
  109.                     }
  110.                 break;
  111.             }
  112.  
  113.         }
  114.     } while (doneFlag ==  FALSE);
  115. }
  116.